#pragma once

namespace ETerrainFlags
{
	enum Flag
	{
		OnlyZeros			= 1 << 0
	};
}

struct TerrainInit
{
public:
	int			m_size;
	float		m_minHeight;
	float		m_maxHeight;

	TerrainInit() :
		m_size(100),
		m_minHeight(-500.0f),
		m_maxHeight(500.0f)
	{}
};

class bTerrain:
	public bObject
{
public:
	bTerrain(btDiscreteDynamicsWorld* world, const bInitData& initdata, const TerrainInit& terraindata);
	~bTerrain();

	virtual void			PreRendering(uint arg);
	virtual void			WriteModelMatrix(float* modelmatrix) const; 

private:
	btHeightfieldTerrainShape*	GenerateHeightmap(const TerrainInit& terraindata);
	void						GenerateMesh( const bInitData& initdata );
	float						GetHeight(int x, int y);

	const RMaterial*			m_material;
	RVertexArray*				m_vertexarray;
	btHeightfieldTerrainShape*	m_collisionShape;

	float*						m_heightmap;
	int							m_size;
	glm::vec2					m_quadCenterPosition;
	uint						m_flags;
};

